<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>属地合同管理员配置</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
    <table class="layout2col1">
        <tbody>
            <tr>
                <td width="30%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_3"></i>组织架构</span>
                        </div>
                        <br/>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <ul id="tree1">
                            </ul>
                        </div>
                    </div>
                </td>
                <td width="70%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_4"></i>省公司合同管理员</span>
                        </div>
                        <div class="sqPanel_body">
                            <div class="btnsBox">
                                <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round" style="display:none">新增</span>
                            </div>
                            <div id="ligergrid" class="sq-grid"></div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>



<script type="text/javascript">
	var grid = null;
	var orgCd = "";
	var orgId = "";
	$(function () {
	var orgNm="事业部";
    tree = $("#tree1").ligerTree({
    	url: '<%=path%>/archive/arcLocalContractUser/initDivisionList.do', 
    	<%-- url: '<%=path%>/system/sysOrg/searchOrgTree.do?orgNm='+orgNm, --%>
        ajaxType: 'get',
        checkbox: false,
        parentIcon: "SqFolder",
        childIcon: "SqLeaf",
        needCancel:false,
        isExpand: false,
        onSelect: onSelectTree,
        onSuccess: function (data) {
            tree.selectNode(data[0]);
        }
    });
	});
	function onSelectTree (node) {
		orgId = node.data.id;
		orgCd = node.data.orgCd;
		grid =  $("#ligergrid").ligerGrid({
			url: '<%=path%>/archive/arcLocalContractUser/initList.do?orgCode='+orgCd,
	    	method : 'get',
	    	async:false,
	        columns: [
	            { display: '属地合同管理人员', name: 'userNames', minWidth: 200, enabledSort:true,
	            	valueField: 'userNames',
	                textField: 'userNames',
	                render: function (item) {
	                    return '<span  title=' + item.userNames + '>' + item.userNames + '</span>' ;
	                }
	            },
	            { display: '所在地名称', name: 'belongCityNm', minWidth: 140, enabledSort:true},
	    		{ display: '操作',
	                isSort: false,
	                width: 120,
	                align:'center',
	                render: function (rowdata, rowindex, value) { 
	            		var h = '';
	        		    h+='<a href="javascript:modifyBtn(';
	                    h+="'"+rowdata.id+"'";
	                    h+=')">修改</a>&nbsp;&nbsp;'
	                    h+='<a href="javascript:deleteBtn(';
	                    h+="'"+rowdata.id+"'";
	                    h+=')">删除</a>'
	                    return h;
	        		}
	            }
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        isScroll: false,
	        checkbox:false,
	        rownumbers:true,
	    });
		if(node.data.orgLvl>="3"){
			$.ajax({
				type:'get',
				url: '<%=path%>/archive/arcLocalContractUser/initList.do?orgCode='+orgCd,
				dataType:'json',
				success:function(data){
					if(data.total==0){
						$("#addBtn").show();
					}else{
						$("#addBtn").hide();
					}
				},
				error:function(data){
				}
			}); 
		}else{
			$("#addBtn").hide();
		}
    }
	function addBtn(){

        $.ligerDialog.SQopen({
            width: 795,
            height:250,
            isResize: true,
            title : '新增省公司合同管理员配置',
            url:'<%=path%>/archive/arcLocalContractUser/toModifyPage.do?orgId='+orgId+'&orgCd='+orgCd,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	function modifyBtn(id){
		$.ligerDialog.SQopen({
            width: 795,
            height:250,
            isResize: true,
            title : '修改省公司合同管理员配置',
            url:'<%=path%>/archive/arcLocalContractUser/toModifyPage.do?id='+id,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	function deleteBtn(id){
		$.ajax({
			type:'get',
			dataType:'json',
			data:{
				"id":id
			},
			url:'<%=path%>/archive/arcLocalContractUser/removeById.do?',
			success:function(msg){
				if(msg.success == 1){
					top.$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "success"
					});
					$("#addBtn").show();
					grid.reload();
				}else{
					top.$.ligerDialog.SQalert({
						content : msg.info,
						SQ_type : "error"
					});
				}
			}
		})
	}
</script>
</body>
</html>